import java.util.Scanner;
public class Main1{
    public static void main(String[] args){
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] chinese,math,english,sum;
        chinese=new int[n+1];
        math=new int[n+1];
        english=new int[n+1];
        sum=new int[n+1];
        for(int i=1;i<=n;i++){
            chinese[i]=scanner.nextInt();
            math[i]=scanner.nextInt();
            english[i]=scanner.nextInt();
            sum[i]=chinese[i]+math[i]+english[i];
        }
        int num=0;
        for(int i=1;i<=n-1;i++){
            for(int j=i+1;j<=n;j++){
                if(sum[i]+10>=sum[j]&&sum[i]-10<=sum[j]){
                    if(chinese[i]+5>=chinese[j]&&chinese[i]-5<=chinese[j]&&math[i]+5>=math[j]&&math[i]-5<=math[j]&&english[i]+5>=english[j]&&english[i]-5<=english[j]){
                        num++;
                    }
                }
            }
        }
        System.out.print(num);
    }
}